local includes = {
    "fairygui",
    "dragonBone",
    "AsyncTCP",
    "Rapid2D_CAudio",
    "ScriptHandlerMgr",
    "jit",
    "bit",
    "tolua"
}
local cjson = require("cjson")

local function export(val, name)
    local api = {}
    local function walk(t, g)
        if type(t) ~= "table" then
            return
        end
        for k, v in pairs(t) do
            local tag = g .. "." .. k
            if type(v) == "table" then
                walk(v, tag)
            else
                if k:sub(1, 2) ~= "__" and k:sub(1, 1) ~= "." then
                    api[tag] = {prefix = g, body = {tag}}
                end
            end
        end
        local mt = getmetatable(t)
        if mt and mt.__index ~= t then
            walk(mt, g)
        end
    end
    walk(val, name)

    local file = ("E:/Cocos/quick-4.0.1/tools/runner/bin/win32/%s-api.json"):format(name)
    local f = io.open(file, "w+")
    f:write(cjson.encode(api))
    f:close()
end

for _, v in pairs(includes) do
    export(_G[v], v)
end
